package com.esunrising.esungsc.advice;

import com.esunrising.esungsc.dto.Result;
import com.esunrising.esungsc.exception.ESUNException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler(ESUNException.class)
    public Result<Void> handleESUNException(ESUNException e){
        log.error(e.getMessage(), e);
        return Result.error(e.getMessage());
    }

    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Result<Void> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e){
        log.error(e.getMessage(), e);
        return Result.error("文件大小超过限制");
    }

    @ExceptionHandler(Exception.class)
    public Result<Void> handleException(Exception e){
        log.error(e.getMessage(), e);
        return Result.error(e.getMessage());
    }
}